package gpstools;

/**
 * @author Marcin Skruch
 */
public class Bounds {

    private double south; /* minimum latitude */
    private double west; /* minimum longitude */
    private double north; /* maximum latitude */
    private double east; /* maximum longitude */

    private boolean empty;

    public Bounds() {
        super();
        empty = true;
    }

    public Bounds extend(Location location) {
        final double lon = location.getLongitude();
        final double lat = location.getLatitude();
        if (empty) {
            north = south = lat;
            east = west = lon;
        } else {
            if (lat > north) {
                north = lat;
            } else if (lat < south) {
                south = lat;
            }
            if (lon > east) {
                east = lon;
            } else if (lon < west) {
                west = lon;
            }
        }
        empty = false;
        return this;
    }

    public Location getSouthEast() {
        return empty ? null : new Point(south, east);
    }

    public Location getNorthWest() {
        return empty ? null : new Point(north, west);
    }

    public Double getMinimumLatitude() {
        return empty ? null : south;
    }

    public Double getMaximumLatitude() {
        return empty ? null : north;
    }

    public Double getMinimumLongitude() {
        return empty ? null : west;
    }

    public Double getMaximumLongitude() {
        return empty ? null : east;
    }
}
